<?php
class commentmodel
{
	var $db;
	var $base;
	function commentmodel(&$base)
	{
		$this->base = $base;
		$this->db = $base->db;
	}
	function post($row)
	{
		$result = $this->db->query("INSERT INTO ".AM_DBTABLEPRE."comment VALUES ('','{$row['uid']}','{$row['id']}','{$row['idtype']}','{$row['authorid']}','{$row['author']}','{$row['created']}','{$row['message']}')");
		return $result;
	}
	function comment_list($id,$idtype,$from,$num)
	{
		$result = $this->db->fetch_all("SELECT * FROM ".AM_DBTABLEPRE."comment WHERE id={$id} AND idtype={$idtype} ORDER BY comment_id DESC LIMIT {$from},{$num}");
		return $result;
	}
	function get_count_by_id($id,$idtype)
	{
		$result = $this->db->fetch_first("SELECT COUNT(*) FROM ".AM_DBTABLEPRE."comment WHERE id={$id} AND idtype = {$idtype}");
		return $result['COUNT(*)'];
	}
	function delete($cid,$uid)
	{
		$result = $this->db->query("DELETE FROM ".AM_DBTABLEPRE."comment WHERE comment_id={$cid} AND uid={$uid}");
		return $this->db->affected_rows();
	}


}
?>